package org.jcnc.IDEology.kernel.kernel;

import org.jcnc.IDEology.kernel.Module;

import java.util.HashMap;
import java.util.Set;

/**
 * The Kernel class manages modules in a HashMap.
 */
public class Kernel{
    /**
     * A HashMap to store modules. The key is the module name, and the value is the Module object.
     */
    private final HashMap<String, Module> modules;

    /**
     * Constructor for the Kernel class. Initializes the modules HashMap.
     */
    public Kernel() {
        modules = new HashMap<>();
    }

    /**
     * Method to get a module by its name.
     * @param name The name of the module
     * @return The Module object
     */
    public Module getModule(String name) {
        return modules.get(name);
    }

    /**
     * Method to remove a module by its name.
     * @param name The name of the module
     */
    public void removeModule(String name) {
        modules.remove(name);
    }

    /**
     * Method to register a module with its name and the Module object.
     * @param name The name of the module
     * @param module The Module object
     */
    public void registerModule(String name, Module module) {
        modules.put(name, module);
    }

    /**
     * Method to start a module by its name.
     * @param name The name of the module
     */
    public void startModule(String name) {
        Module module = modules.get(name);
        if (module != null) {
            module.startModule();
        }
    }

    /**
     * Method to stop a module by its name.
     * @param name The name of the module
     */
    public void stopModule(String name) {
        Module module = modules.get(name);
        if (module != null) {
            module.stopModule();
        }
    }



    /**
     * Method to get all registered module names.
     * @return A set of all registered module names
     */
    public Set<String> getAllRegisteredModules() {
        return modules.keySet();
    }

}
